package com.dragonfly.shutter.DAOIbatisImpls;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.dragonfly.shutter.DAOs.CollectionDAO;
import com.dragonfly.shutter.beans.Collection;

public class CollectionDAOIbaitisImpl extends SqlMapClientDaoSupport implements CollectionDAO {

	public int deleteCollectionById(Integer collectionID) {
		return this.getSqlMapClientTemplate().delete("deleteCollectionById", collectionID);
	}

	public int deleteCollectionByUserId(Integer userID) {
		return this.getSqlMapClientTemplate().delete("deleteCollectionByUserId", userID);
	}

	public Integer insertCollection(Collection collection) {
		return (Integer) this.getSqlMapClientTemplate().insert("insertCollection", collection);
	}

	@SuppressWarnings("unchecked")
	public List<Collection> selectCollectionByUserId(Integer userID) {
		return this.getSqlMapClientTemplate().queryForList("selectCollectionByUserId", userID);
	}

	@SuppressWarnings("unchecked")
	public List<Collection> selectPagedCollectionByUserId(Integer userID,
			Integer minRow, Integer maxRow) {
		Map map = new HashMap();
		map.put("userID", userID);
		map.put("minRow", minRow);
		map.put("maxRow", maxRow);
		
		return this.getSqlMapClientTemplate().queryForList("selectPagedCollectionByUserId", map);
	}

	public Integer selectCollectionCount(Integer userID) {
		return (Integer) this.getSqlMapClientTemplate().queryForObject("selectCollectionCount", userID);
	}

	@SuppressWarnings("unchecked")
	public Integer selectOnePic(Integer userID, String pictureID) {
		Map map = new HashMap();
		map.put("userID", userID);
		map.put("pictureID", pictureID);
		return (Integer) this.getSqlMapClientTemplate().queryForObject("selectOnePic", map);
	}

}
